//
//  setGroupTableView.m
//  yunqiphone
//
//  Created by Maple on 13-10-25.
//  Copyright (c) 2013年 ci123.com. All rights reserved.
//

#import "setGroupTableView.h"

@implementation setGroupTableView

- (id)initWithFrame:(CGRect)frame style:(UITableViewStyle)style
{
    self = [super initWithFrame:frame style:style];
    if (self) {
        self.delegate = self;
        self.dataSource = self;
        self.separatorColor = DefaultBorderColor;
    }
    return self;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  static NSString *identify = @"SetCell";
  UITableViewCell *cell = [self dequeueReusableCellWithIdentifier:identify];
  if(cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identify];
    
    if(Current_device_vesion<7){
      NSString *name = (indexPath.row == 0) ? @"set_top" : @"set_center";
      UIImageView *back = [[UIImageView alloc] initWithImage:[UIImage imageNamed:name]];
      back.frame = CGRectMake(10, 0, 299, 47);
      cell.backgroundView = back;
    
      NSString *downName = (indexPath.row == 0) ? @"set_top_down" : @"set_center_down";
      UIImageView *back_down = [[UIImageView alloc] initWithImage:[UIImage imageNamed:downName]];
      back_down.frame = CGRectMake(10, 0, 299, 47);
      cell.selectedBackgroundView = back_down;
    }
    
    cell.textLabel.backgroundColor = [UIColor clearColor];
    cell.textLabel.textColor = RGBCOLOR(61, 61, 61);
    cell.textLabel.font = [UIFont systemFontOfSize:17];
    cell.textLabel.highlightedTextColor = cell.textLabel.textColor;
    
    cell.detailTextLabel.backgroundColor = [UIColor clearColor];
    cell.detailTextLabel.textColor = RGBCOLOR(141, 141, 141);
    cell.detailTextLabel.font = [UIFont systemFontOfSize:17];
    cell.detailTextLabel.highlightedTextColor = cell.detailTextLabel.textColor;
  }
  if(![_noAccess containsObject:[NSString stringWithFormat:@"%ld%ld", (long)indexPath.section, (long)indexPath.row]]) {
    UIImageView *access= [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 14, 14)];
    access.image = [UIImage imageNamed:@"set_right_open"];
    cell.accessoryView = access;
  }else{
    UIView *view = [[UIView alloc] init];
    cell.selectedBackgroundView = view;
  }
  NSMutableArray *sectionArray = [self.data objectAtIndex:indexPath.section];
  cell.textLabel.text = sectionArray[indexPath.row];
  NSMutableArray *detailArray = [self.detailData objectAtIndex:indexPath.section];
  cell.detailTextLabel.text= detailArray[indexPath.row];
  
  return cell;
}

////设置每个section的cell行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  NSInteger result = 0;
  if ([self.data count]>section) {
    NSMutableArray *sectionArray = [self.data objectAtIndex:section];
    result = (NSInteger)[sectionArray count];
  }
  return result;
  
}

//指定有多少个分区(Section)，默认为1
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  return [self.data count];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  return 47;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  return 1;
}

@end
